//
//  ListViewController.m
//  PlaylistApp
//
//  Created by btang6 on 10/17/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ListView.h"

@implementation ListView

@synthesize playPauseButton, label, currentPlaylist;

// Handles when the play/pause button is pressed
- (IBAction)playPauseButtonPressed
{
    //UIImage *pause = [[[UIImage alloc] initWithContentsOfFile:@"PauseButton.jpg"] autorelease];
    // Toggle between Play and Pause symbol
    //[[self playPauseButton] setImage:pause forState:UIControlStateNormal];
    
    //UIImage *whichButton = [[[UIImage alloc] initWithContentsOfFile:@"PlayButton.jpg"] autorelease];
    UIImage *whichButton = [UIImage imageNamed:@"play.png"];
    if (isPlaying) {
        isPlaying = FALSE;
        //whichButton = [[[UIImage alloc] initWithContentsOfFile:@"PauseButton.jpg"] autorelease];
        whichButton = [UIImage imageNamed:@"pause.png"];
    }
    else {
        isPlaying = TRUE;
    }
    [[self playPauseButton] setImage:whichButton forState:UIControlStateNormal];
    //playPauseButton.imageView.image = whichButton;
}

// ------------------- Default functions -------------------
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Do any additional setup after loading the view from its nib.
    
    [self.navigationItem setTitle:currentPlaylist];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *dirPath = [paths objectAtIndex:0];
    NSString *songPath = [dirPath stringByAppendingFormat:@"/%@.plist", currentPlaylist];
    songs = [NSArray arrayWithContentsOfFile:songPath];
    [songs retain];    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [songs count];
}

/*
 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
 {
 return [songs objectAtIndex:section];
 }
 */

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier] autorelease];
    }
    
    cell.textLabel.text = [songs objectAtIndex:indexPath.row];
    return cell;
}


@end
